package com.tvunetworks.center.device.service.impl;

import com.tvunetworks.center.common.exception.ServerException;
import com.tvunetworks.center.common.model.SendMsgToMsgpipeParam;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.device.constant.DeviceConstant;
import com.tvunetworks.center.device.model.result.ResultConstant;
import com.tvunetworks.center.device.service.MsgpipeService;
import com.tvunetworks.center.device.service.feign.MsgpipeFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: tvucc-aggregator
 * @description: MsgpipeServiceImpl
 * @author lebronchen
 * @create: 2019-04-01 11:35
 **/
@Service
@Slf4j
public class MsgpipeServiceImpl implements MsgpipeService {

    @Autowired
    private MsgpipeFeignService msgpipeFeignService;

    @Override
    public void sendMsgToMsgpipe(String receiver, String msg) {
        log.info("Send msg to msgpipe receiver:{} msg:{}", receiver, msg);
        Result<String> result = msgpipeFeignService.sendMsgToMsgpipe(new SendMsgToMsgpipeParam(false, receiver, msg, DeviceConstant.TimeLockConstant.MSGPIPE_TYPE));
        if (result.assertSuccess()) {
            return;
        }
        log.info("Send msg to msgpipe failed receiver:{} msg:{} result:{}", receiver, msg, result.getErrorInfo());
        ServerException.Exception(ResultConstant.TimeLock.SEND_MESSAGE_MSGPIPE_FAILED);
    }
}
